package com.weetop.cfw.mine.adapter

import android.view.LayoutInflater
import android.view.View
import android.widget.ImageView
import com.blankj.utilcode.util.ConvertUtils
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.coorchice.library.SuperTextView
import com.weetop.cfw.R
import com.weetop.cfw.bean.LeaseSaleBrowsingRecordBean
import com.weetop.cfw.bean.TestBean
import com.weetop.cfw.bean.WorkshopWarehouseListBean
import com.weetop.cfw.constants.UrlConstants
import com.zhy.view.flowlayout.FlowLayout
import com.zhy.view.flowlayout.TagAdapter
import com.zhy.view.flowlayout.TagFlowLayout

class WorkshopBrowseRecordOneAdapter(layoutId:Int, dataList:List<LeaseSaleBrowsingRecordBean.DataBean>):BaseQuickAdapter<LeaseSaleBrowsingRecordBean.DataBean,BaseViewHolder>(layoutId,dataList) {

    override fun convert(helper: BaseViewHolder, item: LeaseSaleBrowsingRecordBean.DataBean?) {
        val textWorkshopImg = helper.getView<ImageView>(R.id.textWorkshopImg)
       val flowWorkshopDesc: TagFlowLayout = helper.getView(R.id.flowWorkshopDesc)
        val tagList = ArrayList<String?>()
        if(item?.isalone.equals("1")){
            tagList.add("独院")
        }else{

        }
        if(item?.haslift.equals("1")){
            tagList.add("电梯")
        }else{

        }
        if(item?.floor?.trim().equals("")){

        }else{
            tagList.add("${item?.floor}层")
        }
        flowWorkshopDesc.adapter = object: TagAdapter<String>(tagList){
            override fun getView(parent: FlowLayout?, position: Int, t: String?): View {
                val textItemWorkshopDescFlowLayoutView = LayoutInflater.from(mContext).inflate(R.layout.layout_item_workshop_desc_flow,parent,false)
                val textItemWorkshopDesc = textItemWorkshopDescFlowLayoutView.findViewById<SuperTextView>(R.id.textItemWorkshopDesc)
                textItemWorkshopDesc.text = tagList[position]
                return textItemWorkshopDescFlowLayoutView
            }
        }
        Glide.with(mContext).load("${UrlConstants.baseUrl}${item?.imgurl}").apply(
            RequestOptions().transforms(
                CenterCrop(),
                RoundedCorners(ConvertUtils.dp2px(5f))
            )
        ).error(R.drawable.cover).into(textWorkshopImg)
        helper.setText(R.id.textWorkshopName,item?.title).setText(R.id.textWorkshopAddress,"地址：${item?.address}")
            .setText(R.id.textWorkshopArea,"面积：${item?.totalarea}㎡")

    }
}